using UnityEngine;

[ExecuteInEditMode]
public class readData : ReadTXT
{
	public bool readflag;

	public string gamelevelname;

	public string gamestepname;

	public string npcname;

	public string attributename;

	public string starname;

	public string dtbname;

	public string tdmname;

	public string ffaname;

	public string surname;

	public string piecename;

	private GameLevel templevel;

	private GameStep tempstep;

	private Attribute tempatt;

	private NPC_ID_num id_num;

	public DataController alldata;

	private PieceData temppiece;

	private weapon_att tempwea;

	private heal_att tempheal;

	private NpcData tempnpc;

	private LevelStar tempstar;

	private DTBData tempdtb;

	private DropItem temp_drop;

	private TDMData temptdm;

	private FFAData tempffa;

	private SurData tempsur;

	private void Update()
	{
		if (readflag)
		{
			readflag = false;
		}
	}

	public void readpiece()
	{
		InitArray(piecename);
		alldata.piecedata.Clear();
		for (int i = 1; i < GetXlength() - 1; i++)
		{
			temppiece = null;
			temppiece = new PieceData();
			temppiece.id = GetInt(i, 0);
			temppiece.type = GetInt(i, 1);
			temppiece.templateid = GetInt(i, 2);
			temppiece.description = GetStr(i, 3);
			alldata.piecedata.Add(temppiece);
		}
	}

	public void readlevel()
	{
		InitArray(gamelevelname);
		alldata.DataLevel.Clear();
		for (int i = 1; i < GetXlength() - 1; i++)
		{
			templevel = null;
			templevel = new GameLevel();
			templevel.jidi1id = GetInt(i, 2);
			templevel.jidi2id = GetInt(i, 3);
			templevel.gamestepid.Add(GetInt(i, 4));
			templevel.gamestepid.Add(GetInt(i, 5));
			templevel.gamestepid.Add(GetInt(i, 6));
			templevel.starid.Add(GetInt(i, 7));
			templevel.starid.Add(GetInt(i, 8));
			templevel.starid.Add(GetInt(i, 9));
			templevel.success_exp = GetInt(i, 10);
			templevel.success_gold = GetInt(i, 11);
			templevel.energy = GetInt(i, 12);
			DropItem dropItem = new DropItem();
			dropItem.dropid = GetInt(i, 13);
			dropItem.gailv = GetInt(i, 14);
			templevel.dropitem.Add(dropItem);
			dropItem = null;
			dropItem = new DropItem();
			dropItem.dropid = GetInt(i, 15);
			dropItem.gailv = GetInt(i, 16);
			templevel.dropitem.Add(dropItem);
			alldata.DataLevel.Add(templevel);
		}
	}

	public void readstep()
	{
		InitArray(gamestepname);
		alldata.DataStep.Clear();
		for (int i = 1; i < GetXlength() - 1; i++)
		{
			tempstep = null;
			tempstep = new GameStep();
			tempstep.ID = GetInt(i, 0);
			tempstep.hitinfo = GetStr(i, 1);
			tempstep.steptype = GetInt(i, 2);
			tempstep.enemy_id_num.Clear();
			for (int j = 0; j < 6 && GetInt(i, 5 + j * 2) != -1; j++)
			{
				id_num = null;
				id_num = new NPC_ID_num();
				id_num.ID = GetInt(i, 5 + j * 2);
				id_num.num = GetInt(i, 6 + j * 2);
				tempstep.enemy_id_num.Add(id_num);
			}
			tempstep.fri_id_num.Clear();
			for (int k = 0; k < 6 && GetInt(i, 17 + k * 2) != -1; k++)
			{
				id_num = null;
				id_num = new NPC_ID_num();
				id_num.ID = GetInt(i, 17 + k * 2);
				id_num.num = GetInt(i, 18 + k * 2);
				tempstep.fri_id_num.Add(id_num);
			}
			tempstep.timelimit = GetFloat(i, 29);
			alldata.DataStep.Add(tempstep);
		}
	}

	public void readattribute()
	{
		InitArray(attributename);
		alldata.DataAttribute.Clear();
		for (int i = 1; i < GetXlength() - 1; i++)
		{
			tempatt = null;
			tempatt = new Attribute();
			tempatt.ID = GetInt(i, 0);
			tempatt.maxspeed = GetInt(i, 3);
			tempwea = null;
			tempwea = new weapon_att();
			tempwea.machgun = GetInt(i, 4);
			tempwea.machgun_pen = GetInt(i, 5);
			tempwea.missile = GetInt(i, 6);
			tempwea.missile_pen = GetInt(i, 7);
			if (GetInt(i, 8) == 1)
			{
				tempwea.havemiss = true;
			}
			else
			{
				tempwea.havemiss = false;
			}
			tempatt.curweapon = tempwea;
			tempheal = null;
			tempheal = new heal_att();
			tempheal.maxhp = GetInt(i, 1);
			tempheal.def = GetInt(i, 2);
			tempatt.curhealatt = tempheal;
			alldata.DataAttribute.Add(tempatt);
		}
	}

	public void readNPC()
	{
		InitArray(npcname);
		alldata.DataNPC.Clear();
		for (int i = 1; i < GetXlength() - 1; i++)
		{
			tempnpc = null;
			tempnpc = new NpcData();
			tempnpc.ID = GetInt(i, 0);
			tempnpc.npctype = GetInt(i, 1);
			tempnpc.npcmode = GetInt(i, 2);
			tempnpc.attribute_id = GetInt(i, 3);
			alldata.DataNPC.Add(tempnpc);
		}
	}

	public void readstar()
	{
		InitArray(starname);
		alldata.DataLevelstar.Clear();
		for (int i = 1; i < GetXlength() - 1; i++)
		{
			tempstar = null;
			tempstar = new LevelStar();
			tempstar.ID = GetInt(i, 0);
			tempstar.type = GetInt(i, 1);
			tempstar.sontype = GetInt(i, 2);
			alldata.DataLevelstar.Add(tempstar);
		}
	}

	public void readDTB()
	{
		InitArray(dtbname);
		alldata.dtbdata.Clear();
		for (int i = 1; i < GetXlength() - 1; i += 9)
		{
			tempdtb = null;
			tempdtb = new DTBData();
			tempdtb.challdata.openlevel = GetInt(i, 1);
			tempdtb.challdata.energy = GetInt(i, 2);
			tempdtb.planeatt = GetInt(i, 3);
			tempdtb.challdata.exp = GetInt(i, 10);
			tempdtb.challdata.money = GetInt(i, 11);
			tempdtb.challdata.diamond = GetInt(i, 12);
			temp_drop = null;
			temp_drop = new DropItem();
			temp_drop.dropid = GetInt(i, 13);
			temp_drop.gailv = GetInt(i, 14);
			tempdtb.challdata.dropitem = temp_drop;
			tempdtb.challdata.falseexp = GetInt(i, 15);
			tempdtb.challdata.falsemoney = GetInt(i, 16);
			for (int j = 0; j < 9; j++)
			{
				tempdtb.buildatt.Add(GetInt(i + j, 6));
			}
			for (int k = 0; k < 3; k++)
			{
				tempdtb.shipatt.Add(GetInt(i + k, 9));
			}
			alldata.dtbdata.Add(tempdtb);
		}
	}

	public void readTDM()
	{
		InitArray(tdmname);
		alldata.tdmdata.Clear();
		for (int i = 1; i < GetXlength() - 1; i++)
		{
			temptdm = null;
			temptdm = new TDMData();
			temptdm.challdata.openlevel = GetInt(i, 1);
			temptdm.challdata.energy = GetInt(i, 2);
			temptdm.planeatt = GetInt(i, 3);
			temptdm.challdata.exp = GetInt(i, 4);
			temptdm.challdata.money = GetInt(i, 5);
			temptdm.challdata.diamond = GetInt(i, 6);
			temp_drop = null;
			temp_drop = new DropItem();
			temp_drop.dropid = GetInt(i, 7);
			temp_drop.gailv = GetInt(i, 8);
			temptdm.challdata.dropitem = temp_drop;
			temptdm.challdata.falseexp = GetInt(i, 9);
			temptdm.challdata.falsemoney = GetInt(i, 10);
			alldata.tdmdata.Add(temptdm);
		}
	}

	public void readFFA()
	{
		InitArray(ffaname);
		alldata.ffadata.Clear();
		for (int i = 1; i < GetXlength() - 1; i++)
		{
			tempffa = null;
			tempffa = new FFAData();
			tempffa.challdata.openlevel = GetInt(i, 1);
			tempffa.challdata.energy = GetInt(i, 2);
			tempffa.planeatt = GetInt(i, 3);
			tempffa.challdata.exp = GetInt(i, 4);
			tempffa.challdata.money = GetInt(i, 5);
			tempffa.challdata.diamond = GetInt(i, 6);
			temp_drop = null;
			temp_drop = new DropItem();
			temp_drop.dropid = GetInt(i, 7);
			temp_drop.gailv = GetInt(i, 8);
			tempffa.challdata.dropitem = temp_drop;
			alldata.ffadata.Add(tempffa);
		}
	}

	public void readSur()
	{
		InitArray(surname);
		alldata.surdata.Clear();
		for (int i = 1; i < GetXlength() - 1; i += 20)
		{
			tempsur = null;
			tempsur = new SurData();
			tempsur.challdata.openlevel = GetInt(i, 2);
			tempsur.challdata.energy = GetInt(i, 3);
			for (int j = 0; j < 20; j++)
			{
				tempsur.enemynum.Add(GetInt(i + j, 4));
				tempsur.enemyatt.Add(GetInt(i + j, 5));
				tempsur.explist.Add(GetInt(i + j, 6));
				tempsur.moneylist.Add(GetInt(i + j, 7));
				tempsur.gemlist.Add(GetInt(i + j, 8));
				tempsur.piecelist.Add(GetInt(i + j, 9));
				tempsur.gailvlist.Add(GetInt(i + j, 10));
			}
			tempsur.challdata.exp = GetInt(i, 6);
			tempsur.challdata.diamond = GetInt(i, 7);
			temp_drop = null;
			temp_drop = new DropItem();
			temp_drop.dropid = GetInt(i, 8);
			temp_drop.gailv = GetInt(i, 9);
			tempsur.challdata.dropitem = temp_drop;
			alldata.surdata.Add(tempsur);
		}
	}
}
